import requests
from config import url, headers_web


class CourseKnowledgeStructure:
    def __init__(self):
        self.url = url
        self.headers = headers_web

    @classmethod
    def get_course_knowledge_point_and_recource(cls, url: str, params, headers):
        """

        :param url:
        :param params:{
                        "courseId":"", # 课程id
                        "pointId":"", # 知识点id
                        "validCode":"", # 验证码（&signKey=123123）
                        "versionId":"" #版本id
                        }
        :param headers:
        :return:object
        """

        url = url + "/courseApi/v1/courseknowledgepoint/resource"

        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def get_course_knowledge_info(cls, url: str, params, headers):
        """
        @Summary:获取课程知识结构信息
        @Description:云课堂教师端-课程建设使用
        :param url:
        :param params:{
                        "courseId":"", # 课程id
                        "validCode":"", # 验证码（courseId={}&signKey=123123）
                        "versionId":"" # 版本id
                        }
        :param headers:
        :return:
        """
        url = url + "/courseApi/v1/courseknowledgestructure"
        r = requests.get(url=url, params=params, headers=headers)

        return r

    @classmethod
    def post_add_knowledge_structure(cls, url: str, params, headers, json):
        """
        @Summary:新增课程知识结构
        @Description:云课堂教师端-课程建设使用
        :param url:
        :param params:validCode:验证码（&signKey=123123）
        :param header:
        :param json:{
                    "content": "" , # 知识结构内容
                    "courseId": "", # 课程id
                    "knowledgePointList": "",
                    "operatorId": "", # 操作人id
                    "operatorName": "", # 操作人姓名
                    "parentId": "", # 父级id
                    "structureType": "", # 知识结构类型
                    "versionId":"" # 版本id
                    }
        :return:
        """
        url = url + "/courseApi/v1/courseknowledgestructure"
        r = requests.post(url=url, params=params, headers=headers, json=json)

        return r

    @classmethod
    def post_sort_knowledge_structure(cls, url: str, params, headers, json):
        """
        @Summary:新增课程知识结构
        @Description:云课堂教师端-课程建设使用
        :param url:
        :param params:{
                        "courseId":"", # 课程id
                        "validCode":"", # 验证码（courseId={}&signKey=123123）
                        "versionId":"" # 版本id
                        "operatorId":"", # 操作人id
                        "operatorName":"" # 操作人姓名
                        }
        :param headers:
        :param json:[{
                        "childList":"", #
                        "id":"", # 知识结构id
                        }]
        :return:
        """
        url = url + "/courseApi/v1/courseknowledgestructure/sort"
        r = requests.post(url=url, params=params, headers=headers, json=json)

        return r

    @classmethod
    def post_del_knowledge_structure(cls, url: str, params, headers, json, parampath):
        """
        @Summary:删除课程知识结构
        @Description:云课堂教师端-课程建设使用
        :param url:
        :param params:validCode:验证码（id={}&signKey=123123）
        :param headers:
        :param json:{
                    "content": "" , # 知识结构内容
                    "courseId": "", # 课程id
                    "knowledgePointList": "",
                    "operatorId": "", # 操作人id
                    "operatorName": "", # 操作人姓名
                    "parentId": "", # 父级id
                    "structureType": "", # 知识结构类型
                    "versionId":"" # 版本id
                    }
        :param parampath:id:知识结构id
        :return:
        """
        url = url + f"/courseApi/v1/courseknowledgestructure/{parampath}/delete"
        r = requests.post(url=url, params=params, headers=headers, json=json)

        return r

    @classmethod
    def post_update_knowledge_structure(cls, url: str, params, headers, json, parampath):
        """
        @Summary:更新课程知识结构
        @Description:云课堂教师端-课程建设使用
        :param url:
        :param params:validCode:验证码（id={}&signKey=123123）
        :param headers:
        :param json:{
                    "content": "" , # 知识结构内容
                    "courseId": "", # 课程id
                    "knowledgePointList": "",
                    "operatorId": "", # 操作人id
                    "operatorName": "", # 操作人姓名
                    "parentId": "", # 父级id
                    "structureType": "", # 知识结构类型
                    "versionId":"" # 版本id
                    }
        :param parampath:id:知识结构id
        :return:
        """
        url = url + f"/courseApi/v1/courseknowledgestructure/{parampath}/update"
        r = requests.post(url=url, params=params, headers=headers, json=json)

        return r

    @classmethod
    def post_link_knowledge_point(cls, url: str, params, headers, json):
        """
        @Summary:更新课程知识结构
        @Description:云课堂教师端-课程建设使用
        :param urlpath:
        :param params: validCode:验证码（id={}&signKey=123123）
        :param headers:
        :param json:{
                    "pointIdList": "" ,
                    "resourceId": "", # 资源id
                    "knowledgePointList": "",
                    "userId": "", # 操作人id
                    "userName": "" # 操作人姓名
                    }
        :return:
        """
        urlpath = url + "/courseApi/v1/courseresource/knowledgepoint"
        r = requests.post(url=urlpath, params=params, headers=headers, json=json)

        return r
